<?php

/**
 * Trida reprezentujici uzivatele
 *
 */
class User extends Zend_Db_Table_Row_Abstract
{

    /**
     *
     * @var User
     */
    private static $_activeUser;

    /**
     *
     * @return User
     */
    public static function getActiveUser()
    {

        if (!is_null(self::$_activeUser))
        {
            return self::$_activeUser;
        }
        else
        {
            $auth = Zend_Auth::getInstance();

            if (!$auth->hasIdentity())
            {
                throw new Exception("No identity");
            }

            $name = $auth->getIdentity();
            $users = new Users();

            self::$_activeUser = $users->findByLastFm($name)->current();
        }

        return self::$_activeUser;
    }

    /**
     *
     * @return integer
     */

    public function getID()
    {
        return $this->id;
    }
    
    /**
     *
     * @return string
     */

    public function getLocale()
    {
        return $this->locale;
    }
    
    /**
     *
     * @return bool
     */

    public function hasAutoplay()
    {
        return (bool)$this->autoplay;
    }

    /**
     *
     * @return bool
     */
    public static function isActiveUser()
    {
        return !is_null(self::$_activeUser);
    }

    /**
     *
     * @return string
     */
    public function getLastFmName()
    {
        return $this->last_fm_username;
    }

    /**
     *
     * @return string
     */

    public function getSessionKey()
    {
        return $this->session_key;

    }

}